# == Schema Information
# Schema version: 8
#
# Table name: categories
#
#  id      :integer(11)   not null, primary key
#  title   :string(255)   default(), not null
#  user_id :integer(11)   not null
#

class Category < ActiveRecord::Base
  belongs_to :user
  has_many :subscriptions

  validates_presence_of :title, :user_id

  def div_id
    "category_#{id}"
  end

  def unreaded_size
    subscriptions.map{ |s| s.items.size}.sum
  end

  def item_data
    subscriptions.map{ |subscription| subscription.item_data}.sum
  end

end
